<%@page import="java.util.List"%>
<%@page import="com.metagurukul.metaspace.models.beans.UserProject"%>
<%@page import="com.metagurukul.metaspace.models.beans.UserWorkDetail"%>
<%@page import="com.metagurukul.metaspace.service.UserService"%>

<%
	if (session.getAttribute("user") == null)
		response.sendRedirect("../index.jsp");
%>

<%@page import="java.util.ArrayList"%>
<%@page import="com.metagurukul.metaspace.service.WorkDetailService"%>
<%@page import="com.metagurukul.metaspace.models.beans.Department"%>
<%@page import="com.metagurukul.metaspace.models.beans.Project"%>
<%@page import="com.metagurukul.metaspace.models.beans.Role"%>
<%@ page language="java"%>
<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html"%>

<%@ page errorPage="/jsp/exceptionHandler.jsp"%>
<%@page import="com.metagurukul.metaspace.models.beans.UserWorkDetail"%>
<%@page import="com.metagurukul.metaspace.service.UserService"%>

<%@page import="com.metagurukul.metaspace.models.beans.UserPersonalDetail"%>
<%
	if (session.getAttribute("user") == null)
		response.sendRedirect("../index.jsp");
%>

<html>
<title>MetaSpace - Work Details</title>
<head>
<link rel="stylesheet" href="../resources/css/style2.css" />
<script type="text/javascript" src="../resources/js/validation.js"></script>

<script type="text/javascript" src="../resources/js/jquery.js"></script>
<SCRIPT type="text/javascript">
	$(document).ready(function() {
		if (window != top)
			top.location.href = location.href;
	});

	window.history.forward();
	function noBack() {
		window.history.forward();
	}
	function search() {
		window.open("/jsp/search.jsp?txt="
				+ document.getElementById("searchTxt").value, "content");
	}
	function goHome() {
		window.location = '/jsp/home.jsp';
	}
</SCRIPT>
<link rel="stylesheet" type="text/css"
	href="../resources/css/masterLayoutStyle.css" />
<link rel="stylesheet" href="../resources/css/style.css" />



</head>

<body onload="noBack();">
	<%
		int userId = -1;
		if (request.getSession().getAttribute("id") != null) {
			userId = (Integer) request.getSession().getAttribute("id");
		}
		UserPersonalDetail userPersonalDetail = UserService
				.getUserPersonalDetail(userId);
		String userName = "Please update Your Name";
		String profilePic = "0male.jpg";
		if (userPersonalDetail == null) {
			response.sendRedirect("/jsp/registrationDetail.jsp");
		} else {
			userName = userPersonalDetail.getName();
			if (userPersonalDetail.getProfilePicPath() != null) {
				profilePic = userPersonalDetail.getProfilePicPath();
			} else {
				profilePic = "0male.jpg";
			}
		}
	%>
	<div id="header">
		<table style="border: 0; width: 100%; height: 100%">
			<tr>
				<td width="25%" align="center"><a href="/jsp/home.jsp"><img
						src="../resources/images/logo.jpg" /> </a></td>
				<td width="35%" align="center"><input type="text"
					style="font-size: 19px; margin-top: 1px" id="searchTxt" size=23 /><input
					type="button" id="invite" class="btn btn-inverse" value="Search"
					onclick="search()" />
				</td>
				<td width="40%">
					<ul id="mainMenu" class="topmenu">
						<li class="topmenu"><a href="/jsp/home.jsp"
							style="height: 20px; line-height: 20px;"><img
								src="../resources/images/home.png" alt="" />Home</a>
						</li>
						<li class="topmenu"><a href="#"
							style="height: 20px; line-height: 20px;"><span><img
									src="../resources/images/samples.png" alt="" />Settings</span> </a>
							<ul>
								<li><a href="/jsp/profile.jsp" target="content">My
										Profile</a>
								</li>
								<li><a href="/jsp/changePassword.jsp" target="content">Change
										Password</a>
								</li>
								<li><a href="/jsp/personalDetails.jsp" target="content">Edit
										Personal Information</a>
								</li>
								<li><a href="/jsp/workDetails.jsp" target="content">Edit
										Work Details</a>
								</li>
							</ul>
						</li>
						<li class="topmenu"><a href="../Logout"
							style="height: 20px; line-height: 20px;">Sign Out</a>
						</li>
					</ul>
				</td>
			</tr>
		</table>
	</div>

	<div id="container">
		<center>
			<div id='leftContainer' class="bigContainer" style="float: left">
				<div id="verticalMenuContainer" class="smallContainers big">
					<ul>
						<li class="menuHead"><center>
								<a href="/jsp/profile.jsp" target="content"> <%
 	out.write(userName);
 %> </a>
							</center>
						</li>
						<li><a href="#"><img
								src="../resources/images/users/<%=profilePic%>" width="160px"
								height="120px" border="1px" style="border-color: GREY"
								alt="<%=profilePic%>" /> </a>
						</li>
						<li><a href="/jsp/changePicture.jsp" target="content">Edit
								Picture </a>
					</ul>
				</div>
				<%
					UserWorkDetail userWorkDetail = UserService
							.getUserWorkDetail(userId);
					boolean flag = false;
					if (userWorkDetail == null) {
						flag = true;
					}
				%>
				<div id="verticalMenuContainer" class="smallContainers medium">
					<ul style="text-align: left;">
						<li class="menuHead">Job Details</li>
						<li><b>Department : </b> <span style="color: gray"> <%
 	if (!flag) {
 		out.println(userWorkDetail.getDepartmentName());
 	}
 %> </span></li>
						<li><b>Project : </b><span style="color: gray"> <%
 	if (!flag && userWorkDetail.getUserProjectList().size() > 0) {
 		out.println(userWorkDetail.getUserProjectList().get(0)
 				.getProjectName());
 	}
 %> </span></li>
						<li><b>Role : </b><span style="color: gray"> <%
 	if (!flag) {
 		out.println(userWorkDetail.getRoleName());
 	}
 %> </span></li>
					</ul>
				</div>
			</div>
			
			<div id='centerBody' style="font-size: 20px;" >
				<%
			userId = -1;
			if (request.getSession().getAttribute("id") != null) {
				userId = (Integer) request.getSession().getAttribute("id");
			}
			userWorkDetail = UserService
					.getUserWorkDetail(userId);
		%>
		<html:form action="workDetailsAction" method="post"
			onsubmit="return validateWorkDetails(this);">
			<div style="width: 300px; height: 500px; overflow: none">
				<fieldset style="width: 300px; padding-left: 15px">
					<legend>Work Details Information:</legend>
					<br /> Department:
					<html:select name="WorkDetailsForm" property="department"
						style="width: 150px">
						<%
							
						%>



						<option value="-1">Select</option>
						<%
							List<Department> departmentList = WorkDetailService
											.getDepartmentList();
									for (int i = 0; i < departmentList.size(); i++) {
										Department d = departmentList.get(i);
										if (null != userWorkDetail
												&& userWorkDetail.getDeptId() == d.getDeptId()) {
											out.print("<option selected='selected' value='"
													+ d.getDeptId() + "'>" + d.getDeptName()
													+ "</option>");
										} else {
											out.print("<option value='" + d.getDeptId() + "'>"
													+ d.getDeptName() + "</option>");
										}

									}
						%>
					</html:select>
					&nbsp;&nbsp;
					<div id="error_department" style="color: red;">
						<html:errors property="department" />
					</div>
					<br /> <br /> Project:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<html:select name="WorkDetailsForm" property="project"
						style="width: 150px">
						<option value="-1">Select</option>
						<%
							List<Project> projectList = WorkDetailService
											.getProjectList();
									for (int i = 0; i < projectList.size(); i++) {
										Project p = projectList.get(i);
										if (null != userWorkDetail) {
											List<UserProject> up = userWorkDetail
													.getUserProjectList();
											if (up.size() > 0
													&& up.get(0).getProjectId() == p
															.getProjectId()) {
												out.print("<option selected='selected' value='"
														+ p.getProjectId() + "'>"
														+ p.getProjectName() + "</option>");
											} else {
												out.print("<option value='" + p.getProjectId()
														+ "'>" + p.getProjectName()
														+ "</option>");
											}
										} else {
											out.print("<option value='" + p.getProjectId()
													+ "'>" + p.getProjectName() + "</option>");
										}
									}
						%>
					</html:select>
					&nbsp;&nbsp;
					<div id="error_project" style="color: red;">
						<html:errors property="project" />
					</div>
					<br /> <br />
					Role:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

					<html:select name="WorkDetailsForm" property="role"
						style="width: 150px">
						<option value="-1">Select</option>
						<%
							List<Role> roleList = WorkDetailService.getRoleList();
									for (int i = 0; i < roleList.size(); i++) {
										Role r = roleList.get(i);
										if (null != userWorkDetail
												&& userWorkDetail.getRoleId() == r.getRoleId()) {
											out.print("<option selected='selected' value='"
													+ r.getRoleId() + "'>" + r.getRoleName()
													+ "</option>");
										} else {
											out.print("<option value='" + r.getRoleId() + "'>"
													+ r.getRoleName() + "</option>");
										}
									}
						%>
					</html:select>
					&nbsp;&nbsp;
					<div id="error_role" style="color: red;">
						<html:errors property="role" />
					</div>
					<br /> <br />
					<div align="center">
						<html:submit value="continue" property="continue" styleClass="btn btn-inverse"/>
						<input type="button" name="cancel" value="Cancel"
							onclick="goHome()" class="btn btn-inverse"/>
					</div>
				</fieldset>
			</div>
		</html:form>

			</div>
		</center>
		<div id="rightContainer" class="bigContainer" style="float: right">
			<center>
				<div id="verticalMenuContainer" class="smallContainers big">
					<ul>
						<li class="menuHead">Team Members</li>
					</ul>
					List of Team Members will be displayed here as an optional feature.
				</div>
				<div id="verticalMenuContainer" class="smallContainers big">
					<ul>
						<li class="menuHead">Birthday Notifications</li>
					</ul>
					List Members having birthday today will be displayed here as an
					optional feature.
				</div>
			</center>
		</div>
	</div>
	<jsp:include page="/jsp/footer.jsp"></jsp:include>
</body>
</html>
</head>